//
//  IpsWebVC.m
//  Xspcf
//
//  Created by sunshine on 16/12/10.
//  Copyright © 2016年 小小算盘. All rights reserved.
//

#import "JxWebVC.h"

@interface JxWebVC ()<UIWebViewDelegate>
{
    UIWebView *_web;
}
@end

@implementation JxWebVC

- (void)viewDidLoad {
    [super viewDidLoad];
    _web = [[UIWebView alloc]init];
    [self.view addSubview:_web];
    [_web lt_All:SunEdgesMake(0, 0, 0, 0) save:YES];
    _web.delegate = self;
    [[Sun shareSun]showActivity:self];
    
    [self start];
    
    
    // Do any additional setup after loading the view.
}

- (void)start{
    NSURL *url = [NSURL URLWithString:self.url];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:url];
    [request setHTTPMethod: @"POST"];
//    self.param = [self URLEncodedString:self.param];
    [request setHTTPBody: [self.param dataUsingEncoding: NSUTF8StringEncoding]];
    [_web loadRequest: request];
}


- (NSString *)URLEncodedString:(NSString *)str
{
    NSString *unencodedString = str;
    NSString *encodedString = (NSString *)
    CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                              (CFStringRef)unencodedString,
                                                              NULL,
                                                              (CFStringRef)@"+",
                                                              kCFStringEncodingUTF8));
    return encodedString;
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    [[Sun shareSun]hideAll];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [[Sun shareSun]hideAll];
    if (!self.title) {
        self.title = [_web stringByEvaluatingJavaScriptFromString:@"document.title"];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
